/**
 * 
 */
package com.quanyan.common.mail;


import java.util.StringTokenizer;


/**
 * @author administrator
 *
 */


public class EmailUtils {


	private static EmailUtils emailUtils = new EmailUtils();

	private EmailUtils(){}

	public void sendTextEmails(String emails, String subject, String text){
       sendEmail(emails,subject,text,"text");
	}

	public void sendHtmlEmails(String emails, String subject, String text){
		sendEmail(emails,subject,text,"html");
	}

	private void sendEmail(String emails, String subject, String text, String type){
		StringTokenizer token = new StringTokenizer(emails, ";");
		//这个类主要来发送邮件
		SimpleMailSender sms = new SimpleMailSender();

		MailSenderInfo mailInfo = null;
		while(token.hasMoreTokens()){
			mailInfo = new MailSenderInfo();
			mailInfo.setMailServerHost("smtp.mxhichina.com");
			mailInfo.setMailServerPort("25");
			mailInfo.setValidate(true);
			mailInfo.setUserName("developer@quncaotech.com");
			mailInfo.setPassword("Asdf1234");//您的邮箱密码
			mailInfo.setFromAddress(mailInfo.getUserName());
			mailInfo.setToAddress(token.nextToken());
			mailInfo.setSubject(subject);
			mailInfo.setContent(text);
			if (type.equals("text")){
				sms.sendTextMail(mailInfo);//发送文体格式
			}else{
				SimpleMailSender.sendHtmlMail(mailInfo);//发送html格式
			}
		}
	}



	public static EmailUtils getInstance(){
        return emailUtils;
	}

	public static void main(String[] args){
//		getInstance().sendHtmlEmails("zijun.song@quncaotech.com", "nihao", "<html><head></head><body><p style='color:red;font-size:24px;'>test</p></body></html>");
	}
}
